﻿using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace AI_Tank.Game
{
    public class ParseLegStartData
    {
       
        public static LegStartData GetMapData(string dataStr)
        {
            JObject obj;
            obj = JObject.Parse(dataStr);
            int width = (int)obj["msg_data"]["map"]["width"];
            int height = (int)obj["msg_data"]["map"]["height"];
            JArray teamObj;
            teamObj = (JArray)obj["msg_data"]["teams"];
            int teamA_ID = (int)teamObj[0]["id"];
            int teamB_ID = (int)teamObj[1]["id"];
            int[] myPlayers = new int[4];
            int[] enemyPlayers = new int[4];

            for (int i = 0; i < 4; i++)
                {
                    myPlayers[i] = (int)teamObj[0]["players"][i];
                }
            for (int i = 0; i < 4; i++)
            {
                enemyPlayers[i] = (int)teamObj[1]["players"][i];
            }

            LegStartData legStartData = new LegStartData(width, height, teamA_ID, teamB_ID, myPlayers, enemyPlayers);
            //MessageBox.Show(legStartData.MapWidth.ToString() + "\n" + legStartData.MapHeight + "\n" + legStartData.TeamA_ID + "\n" + legStartData.PlayerAs[3]);
            GV.MapSize_X = width;
            GV.MapSize_Y = height;
            return legStartData;
        }
    }

}
